﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Web;

namespace MyControl
{
    public partial class CtrlLib
    {

        public enum ControlType
        { 
            Hidden,
            Label,
            Input,
            Textarea,
            Select,
            FileUpload,
            ImageUpload,
            Link,
            Image,
            Password,
            HTMLEditor,
            RadioBox,
            CheckBox
        }

        public class CommonAttribute
        {
            public string Name;
            public string ID;
            public string Class;
            public string Style;
            public string OnClick;
            public string OnFocus;
            public string OnChange;
            public string OnBlur;
            public string OnDblClick;
            public string OnLoad;
            public string OnKeyUp;
            public string OnKeyDown;
            public string OnKeyPress;
            public string OnSelect;
            public string Value;
            //public string[] _Attrs = new string[] { "Name", "ID", "Class", "Style", "OnClick", "OnFocus", "OnChange", "OnBlur", "OnDblClick", "OnLoad", "Value" };
            //public Dictionary<string, string> Attributes;
            public string _GetAttributeString()
            {
                string AttrStr = "{0}=\"{1}\"";
                StringBuilder sb = new StringBuilder();
                if (Name != null)
                {
                    sb.AppendFormat(AttrStr, "name", this.Name);
                }
                if (ID != null)
                {
                    sb.AppendFormat(AttrStr, "id", this.ID);
                }
                if (Class != null)
                {
                    sb.AppendFormat(AttrStr, "class", this.Class);
                }
                if (Style != null)
                {
                    sb.AppendFormat(AttrStr, "style", this.Style);
                }
                if (OnClick != null)
                {
                    sb.AppendFormat(AttrStr, "onclick", this.OnClick);
                }
                if (OnFocus != null)
                {
                    sb.AppendFormat(AttrStr, "onfocus", this.OnFocus);
                }
                if (OnChange != null)
                {
                    sb.AppendFormat(AttrStr, "onchange", this.OnChange);
                }
                if (OnBlur != null)
                {
                    sb.AppendFormat(AttrStr, "onblur", this.OnBlur);
                }
                if (OnDblClick != null)
                {
                    sb.AppendFormat(AttrStr, "ondblclick", this.OnDblClick);
                }
                if (OnLoad != null)
                {
                    sb.AppendFormat(AttrStr, "onload", this.OnLoad);
                }
                if (OnKeyUp != null)
                {
                    sb.AppendFormat(AttrStr, "onkeyup", this.OnKeyUp);
                }
                if (OnKeyDown != null)
                {
                    sb.AppendFormat(AttrStr, "onkeydown", this.OnKeyDown);
                }
                if (OnKeyPress != null)
                {
                    sb.AppendFormat(AttrStr, "onkeypress", this.OnKeyPress);
                }
                if (OnSelect != null)
                {
                    sb.AppendFormat(AttrStr, "onselect", this.OnSelect);
                }

                return sb.ToString();
            }
        }

        public class Hidden
        {
            public string Name;
            public string ID;
            private string Template = "<input type=\"hidden\" {0} {1} />";
            public override string ToString()
            {
                return string.Format(this.Template, string.IsNullOrEmpty(Name) == false ? "name=\"" + Name + "\"" : "", string.IsNullOrEmpty(ID) == false ? "id=\"" + ID + "\"" : "");
            }
        }

        public class Input : CommonAttribute
        {
            private string Template = "<input type=\"text\" {0} />";
            public override string ToString()
            {
                return string.Format(this.Template, this._GetAttributeString());
            }
        }

        public class Textarea
        {
            public string Name;
            public string ID;
            public string Class;
            public string Style;
            public string OnClick;
            public string OnFocus;
            public string OnBlur;
            public string Value;
        }

    }
}
